/*

	多表查询	

*/

var mysql = require('mysql');

var connection = mysql.createConnection({
	host: 'localhost',
	port: 3306,
	database: 'test',
	user: 'root',
	password: '123456'
});

connection.connect(function(err){
	if(err)
		console.log('连接失败');
	else{
		console.log('连接成功');
		var sqlStr = 'select genres.id, genres.name, books.id, books.genreid, books.name from genres inner join books on genres.id=books.genreid;';
		// var sqlStr = 'select genres.id id1, genres.name name1, books.id, books.genreid, books.name from genres inner join books on genres.id=books.genreid;';
		// connection.query({sql:sqlStr, nestTables: true}, function(err, result){
		connection.query({sql:sqlStr, nestTables: "_"}, function(err, result){
			if(err)
				console.log('连接失败');
			else{
				console.log(result);
				connection.end();
			}
		})
	}
});


// select genres.id, genres.name, books.id, books.genreid, books.name from genres inner join books on genres.id=books.genreid;